package org.yak.common.utils;

import java.util.Random;
import java.util.UUID;

public class RandomUtil {
	 /**
     * 构造函数
     */
    private RandomUtil()
    {

    }

    /**
     * 随机生成4位验证码（1001~9999）
     *
     * @author fengc
     * @return 4位验证码
     */
    public static final String createValidateNum()
    {
        Random ran = new Random();
        int ranNum = ran.nextInt(9999);
        while (ranNum <= 1000)
        {
            ranNum = ran.nextInt(9999);
        }
        return String.valueOf(ranNum);
    }

    /**
     * 根据传入的长度生成验证码
     *
     * @author yuewei
     * @param length
     *            验证码长度
     * @return 随机验证码
     */
    public static final String createValidateNum(int length)
    {
        StringBuffer vailCode = new StringBuffer(length);

        for (int i = 0; i < length; i++)
        {
            int rad = (int) (Math.random() * 10);
            vailCode.append(rad);
        }

        return vailCode.toString();
    }
    
    /**
    *
    * @方法没描述：获取唯一序列
    * @author xq
    * @return
    */
   public static final String getRandom(){
   	String random = UUID.randomUUID().toString();
   	return random.replace("-", "").toUpperCase();
   }
}
